package fr.umlv.jee.jawp.data;
import java.io.ObjectInputStream.GetField;
import java.net.UnknownHostException;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.Mongo;
import com.mongodb.MongoException;

import fr.umlv.jee.jawp.persistence.dao.CategoryDAO;
import fr.umlv.jee.jawp.persistence.dao.OrderDAO;
import fr.umlv.jee.jawp.persistence.dao.ProductDAO;
import fr.umlv.jee.jawp.persistence.object.Category;
import fr.umlv.jee.jawp.persistence.object.Order;
import fr.umlv.jee.jawp.persistence.object.Product;
import fr.umlv.jee.jawp.persistence.object.Status;


public class Main {

	public static void main(String[] args) throws UnknownHostException, MongoException {
//		/* clean the databases */
//
//		CategoryDAO category = new CategoryDAO();
//		category.clearDB();
//
//		OrderDAO order = new OrderDAO();
//		order.clearDB();
//
//		ProductDAO product = new ProductDAO();
//		product.clearDB();
//
//		/* add datas */
//
//		// categories
//		category.createNewCategory("Musique");
//		category.createNewCategory("Livres");
//		category.createNewCategory("Films");
//		category.createNewCategory("Jeux vidéo");
//
//		// products
//		product.createNewProduct("B005QJZ5FA", "Lana Del Rey - Born to die", 0, 10);
//		product.createNewProduct("B00723FC3I", "Sexion D'Assaut - L'Apogee", 0, 10);
//		product.createNewProduct("B003U7RP3U", "Serj Tankian - Imperfect Harmonies", 0, 10);
//		product.createNewProduct("B00004SGS5", "L.T.J. Bukem - Journey Inwards", 0, 10);
//		Product tryo = product.createNewProduct("B001RDJ3I4", "Tryo - Mamagubida", 0, 10);
//
//		product.createNewProduct("2290019437", "George R.R. Martin - Le Trône de fer l'Intégrale, Tome 1", 1, 10);
//		Product lesFourmis = product.createNewProduct("2253063339", "Bernard Werber - Les fourmis", 1, 10);
//		product.createNewProduct("2035834252", "Victor Hugo - Les Misérables", 1, 10);
//		Product notebook = product.createNewProduct("0446605239", "Nicholas Sparks - The Notebook", 1, 10);
//		product.createNewProduct("2035859166", "Jean Racine - Phèdre", 1, 10);
//
//		Product starwars = product.createNewProduct("B004HYGSXS", "Star Wars - L'intégrale de la saga", 2, 10);
//		product.createNewProduct("B0057YFYWS", "Battlestar Galactica - L'intégrale", 2, 10);
//		product.createNewProduct("B0049PNOMS", "Aladdin", 2, 10);
//
//		product.createNewProduct("B006B497OY", "Assassin's Creed : revelations - PlayStation 3", 3, 10);
//		Product spore = product.createNewProduct("B001C4QLEC", "Spore Creatures - Windows", 3, 10);
//		product.createNewProduct("B003H4QT8I", "POKéMON version blanche - Nintendo DS", 3, 10);
//
//		// orders
//
//		Order o1 = order.createNewOrder("manon.barbier@gmail.com");
//		order.addProduct(o1, tryo);
//		order.addProduct(o1, notebook);
//		order.setStatus(o1, Status.ORDERED);
//
//		Order o2 = order.createNewOrder("manon.barbier@gmail.com");
//		order.addProduct(o2, starwars);
//		order.addProduct(o2, spore);
//		order.addProduct(o2, lesFourmis);
//		order.setStatus(o2, Status.ORDERED);
		
		
		
		
		
		
		

		Mongo mongo = new Mongo();
		DB db = mongo.getDB("JAWP_DB");
		
		DBCollection category = db.getCollection("Categories");
		DBCollection order = db.getCollection("Orders");
		DBCollection product = db.getCollection("Products");
		DBCollection oProduct = db.getCollection("OrderedProduct");
		

		/* clean the databases */

		category.drop();
		product.drop();
		order.drop();
		oProduct.drop();

		/* add datas */

		// categories
		BasicDBObject document = new BasicDBObject();
		document.put("id", 0);
		document.put("name", "Musique");
		document.put("motherCategoryId", -1);
		category.insert(document);
		
		document.clear();
		document.put("id", 1);
		document.put("name", "Livres");
		document.put("motherCategoryId", -1);
		category.insert(document);
		
		document.clear();
		document.put("id", 2);
		document.put("name", "Films");
		document.put("motherCategoryId", -1);
		category.insert(document);
		
		document.clear();
		document.put("id", 3);
		document.put("name", "Jeux vidéo");
		document.put("motherCategoryId", -1);
		category.insert(document);

		// products
		
		document.clear();
		document.put("ASIN", "B005QJZ5FA");
		document.put("name", "Lana Del Rey - Born to die");
		document.put("categoryId", 0);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B00723FC3I");
		document.put("name", "Sexion D'Assaut - L'Apogee");
		document.put("categoryId", 0);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B003U7RP3U");
		document.put("name", "Serj Tankian - Imperfect Harmonies");
		document.put("categoryId", 0);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B00004SGS5");
		document.put("name", "L.T.J. Bukem - Journey Inwards");
		document.put("categoryId", 0);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B001RDJ3I4");
		document.put("name", "Tryo - Mamagubida");
		document.put("categoryId", 0);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		//----------------------
		
		document.clear();
		document.put("ASIN", "2290019437");
		document.put("name", "George R.R. Martin - Le Trône de fer l'Intégrale, Tome 1");
		document.put("categoryId", 1);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "2253063339");
		document.put("name", "Bernard Werber - Les fourmis");
		document.put("categoryId", 1);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "2035834252");
		document.put("name", "Victor Hugo - Les Misérables");
		document.put("categoryId", 1);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "0446605239");
		document.put("name", "Nicholas Sparks - The Notebook");
		document.put("categoryId", 1);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "2035859166");
		document.put("name", "Jean Racine - Phèdre");
		document.put("categoryId", 1);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		//----------------------
		
		document.clear();
		document.put("ASIN", "B004HYGSXS");
		document.put("name", "Star Wars - L'intégrale de la saga");
		document.put("categoryId", 2);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B0057YFYWS");
		document.put("name", "Battlestar Galactica - L'intégrale");
		document.put("categoryId", 2);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B0049PNOMS");
		document.put("name", "Aladdin");
		document.put("categoryId", 2);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		//----------------------
		
		document.clear();
		document.put("ASIN", "B006B497OY");
		document.put("name", "Assassin's Creed : revelations - PlayStation 3");
		document.put("categoryId", 3);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B001C4QLEC");
		document.put("name", "Spore Creatures - Windows");
		document.put("categoryId", 3);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		document.clear();
		document.put("ASIN", "B003H4QT8I");
		document.put("name", "POKéMON version blanche - Nintendo DS");
		document.put("categoryId", 3);
		document.put("quantity", 0);
		document.put("limit", 0);
		document.put("responsible", "");
		product.insert(document);
		
		// orders
		
		document.clear();
		document.put("id", 0);
		document.put("customer", "manon.barbier@gmail.com");
		document.put("status", Status.ORDERED.getName());
		order.insert(document);
		
		document.clear();
		document.put("order", 0);
		document.put("product", "B001RDJ3I4");
		document.put("quantity", 1);
		oProduct.insert(document);
		
		document.clear();
		document.put("order", 0);
		document.put("product", "0446605239");
		document.put("quantity", 1);
		oProduct.insert(document);
		
		//--------------------
		
		document.clear();
		document.put("id", 1);
		document.put("customer", "manon.barbier@gmail.com");
		document.put("status", Status.ORDERED.getName());
		order.insert(document);
		
		document.clear();
		document.put("order", 1);
		document.put("product", "B004HYGSXS");
		document.put("quantity", 1);
		oProduct.insert(document);
		
		document.clear();
		document.put("order", 1);
		document.put("product", "B001C4QLEC");
		document.put("quantity", 1);
		oProduct.insert(document);
		
		document.clear();
		document.put("order", 1);
		document.put("product", "2253063339");
		document.put("quantity", 1);
		oProduct.insert(document);
		
		
		
//		CategoryDAO cdao = new CategoryDAO();
//		OrderDAO odao = new OrderDAO();
//		ProductDAO pdao = new ProductDAO();
//		
//		for(Category c : cdao.getCategories())
//			System.out.println(c);
//		System.out.println();
//		
//		for(Product p : pdao.getProducts())
//			System.out.println(p);
//		System.out.println();
//		
//		for(Order o : odao.getOrders()){
//			System.out.println(o);
//			for(Product p : odao.getProductByOrder(o))
//				System.out.println("\t"+p);
//		}
//		System.out.println();
		
	}

}
